<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Test for equality in constant-time</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.sodium-increment.html">« sodium_increment</a></li>
      <li style="float: right;"><a href="function.sodium-memzero.html">sodium_memzero »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.sodium.html">Sodium 函数</a></li>
    <li>Test for equality in constant-time</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.sodium-memcmp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sodium_memcmp</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.2.0, PHP 8)</p><p class="refpurpose"><span class="refname">sodium_memcmp</span> &mdash; <span class="dc-title">Test for equality in constant-time</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sodium-memcmp-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sodium_memcmp</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string1</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string2</code></span>): <span class="type">int</span></div>

  <p class="para rdfs-comment">
   Compare two strings in constant-time.
  </p>
  <p class="para">
   In practice, you almost always want to use <span class="function"><a href="function.hash-equals.html" class="function">hash_equals()</a></span> instead,
   since it provides the same logic but returns a <span class="type">bool</span> instead of an
   <span class="type">int</span>. However, if you&#039;re using the return value of a comparison in a
   calculation that&#039;s timing-sensitive, and worried about timing leaks with bool-to-int
   conversions, <span class="function"><strong>sodium_memcmp()</strong></span> is an ideal replacement.
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-function.sodium-memcmp-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">string1</code></dt>

    <dd>

     <p class="para">
      String to compare
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">string2</code></dt>

    <dd>

     <p class="para">
      Other string to compare
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sodium-memcmp-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns <code class="literal">0</code> if both strings are equal; <code class="literal">-1</code> otherwise.
  </p>
 </div>



</div></div></div></body></html>